package com.dingding.dao.userorderdao.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.bean.databean.push.PushAutomaticCancelOrder;
import com.dingding.bean.databean.push.PushCancelOrder;
import com.dingding.bean.databean.push.PushConfirmArrival;
import com.dingding.bean.databean.push.PushPassengerPay;
import com.dingding.bean.databean.request.ReqGetLastUserOrder;
import com.dingding.bean.databean.request.ReqGetNearbyOrderList;
import com.dingding.bean.databean.request.ReqGetNearbyUserList;
import com.dingding.bean.databean.request.ReqGetUserOrder;
import com.dingding.bean.databean.request.ReqPublishAboutCar;
import com.dingding.bean.databean.response.DataResponse;
import com.dingding.bean.databean.response.NearbyOrderList;
import com.dingding.bean.databean.response.OrderList;
import com.dingding.bean.databean.response.ResCompetitiveOrder;
import com.dingding.bean.databean.response.ResGetLastUserOrder;
import com.dingding.bean.databean.response.ResGetOrderInfo;
import com.dingding.bean.databean.response.ResGetUserOrder;
import com.dingding.bean.entity.Userroute;
import com.dingding.common.core.beans.Userordert;
import com.dingding.common.core.config.ServiceCode;
import com.dingding.common.core.util.DateFormatUtil;
import com.dingding.common.core.util.GetDistanceUtil;
import com.dingding.common.core.util.ToolUtil;
import com.dingding.dao.basedao.impl.BaseDaoImpl;
import com.dingding.dao.sql.UserOrderDaoSql;
import com.dingding.dao.userorderdao.IUserOrderTDao;
import com.dingding.util.ComparatorUtil;

public class UserOrderTDaoImpl extends BaseDaoImpl<Userordert> implements IUserOrderTDao {

	/**
	 * 
	 * @Title: convertBean @Description:发布订单将客户端请求bean转换成 @param
	 *         reqPublishAboutCar 客户端数据请求bean userordert 数据保存bean @author
	 *         cheshaowei @throws
	 * 
	 */
	public void convertBean(ReqPublishAboutCar reqPublishAboutCar, Userordert userordert) {

		// 下单城市
		userordert.setPayCity(reqPublishAboutCar.getPayCity());
		// 发布者ID
		userordert.setPlaceOrderUserId(reqPublishAboutCar.getPlaceOrderUserId());
		// 下单类型+用户角色类型=3
		userordert.setOrderType(3 - reqPublishAboutCar.getUserType());
		// 出发时间
		userordert.setSetOutTime(DateFormatUtil.yyyy_MM_dd_HHmmss(reqPublishAboutCar.getSetOutTime()));
		// 起点
		userordert.setStartAddress(reqPublishAboutCar.getStartAddress());
		// 起点经度
		userordert.setStartLongitude(reqPublishAboutCar.getStartLongitude());
		// 起点纬度
		userordert.setStartLatitude(reqPublishAboutCar.getStartLatitude());
		// 终点
		userordert.setEndAddress(reqPublishAboutCar.getEndAddress());
		// 终点经度
		userordert.setEndLongitude(reqPublishAboutCar.getEndLongitude());
		// 终点纬度
		userordert.setEndLatitude(reqPublishAboutCar.getEndLatitude());
		// 距离
		userordert.setDistance(reqPublishAboutCar.getDistance());
		// 红包
		userordert.setRedBag(reqPublishAboutCar.getRedBag());
		// 留言
		userordert.setMessage(reqPublishAboutCar.getMessage());
		// 人数
		userordert.setNumber(reqPublishAboutCar.getNumber());
		// 总金额
		userordert.setTotalMoney(reqPublishAboutCar.getTotalMoney());
		// 设置叮币默认值
		userordert.setPayMoney(new BigDecimal(0));
		// 设置支付宝支付金额
		userordert.setAlipayMoney(new BigDecimal(0));

	}

	/**
	 * @Title: getPassengerPayPushInfo @Description: 乘客支付-获取给司机发送短信和推送的消息 @param
	 *         driverId 司机Id @author yhq @return void 返回类型 @throws
	 */
	@Override
	public PushPassengerPay getPassengerPayPushInfo(String passengerId, String driverId) {

		// 创建乘客支付成功，给司机推送Bean
		PushPassengerPay pushPassengerPay = new PushPassengerPay();

		// 根据司机Id,获取司机信息
		Object[] obj = null;
		try {
			obj = super.sqlQueryUnResultObj(UserOrderDaoSql.PASSENGER_PAY_PUSH, false, passengerId, driverId);
		} catch (Exception e) {
			log.info("乘客支付获取推送内容时出现异常  类：" + this.getClass() + " getPassengerPayPushInfo()", e);
		}

		// 判断司机信息是否为空
		if (obj != null && obj.length > 0) {

			// 将司机信息赋值给pushPassengerPay
			this.getPushPassengerPay(obj, pushPassengerPay);
		}

		return pushPassengerPay;
	}

	/**
	 * @Title: getPassengerPay @Description:
	 *         将Object[]类型转为PushPassengerPay @param obj 司机信息 @param
	 *         pushPassengerPay 推送对象 @return PushPassengerPay 返回类型 @throws
	 */
	public void getPushPassengerPay(Object[] obj, PushPassengerPay pushPassengerPay) {

		// 司机Id(推送Id)
		if (obj[0] != null) {
			pushPassengerPay.setDriverId(obj[0].toString());
		}
		// 设备类型
		if (obj[1] != null) {
			// 设备类型 1:iOS 2:Android
			String deviceType = obj[1].toString();

			if (deviceType.equals("1")) { // 设备类型为：iOS
				pushPassengerPay.setLoginEquipment("iOS");
			} else if (deviceType.equals("2")) { // 设备类型为：Android
				pushPassengerPay.setLoginEquipment("Android");
			}

		}
		// 司机电话
		if (obj[2] != null) {
			pushPassengerPay.setTellPhone(obj[2].toString());
		}
		// 乘客姓名
		if (obj[3] != null) {
			pushPassengerPay.setPassengerName(obj[3].toString());
		}
		// 车牌号
		if (obj[4] != null) {
			pushPassengerPay.setLisencePlate(obj[4].toString());
		}
		// 司机名称
		if (obj[5] != null) {
			pushPassengerPay.setDriverName(obj[5].toString());
		}
	}

	/**
	 * @Title: getConfirmArrival @Description: 乘客确认到达-获取给司机发送短信和推送的消息 @param
	 *         passengerId 乘客Id @param driverId 司机Id @author yhq @return
	 *         PushConfirmArrival 返回类型 @throws
	 */
	@Override
	public PushConfirmArrival getConfirmArrival(String passengerId, String driverId) {

		// 创建乘客支付成功，给司机推送Bean
		PushConfirmArrival pushConfirmArrival = new PushConfirmArrival();

		// 根据司机Id,获取司机信息
		Object[] obj = null;
		try {
			obj = super.sqlQueryUnResultObj(UserOrderDaoSql.PASSENGER_PAY_PUSH, false, passengerId, driverId);
		} catch (Exception e) {
			log.info("乘客支付获取推送内容时出现异常  类：" + this.getClass() + " getPassengerPayPushInfo()", e);
		}

		// 判断司机信息是否为空
		if (obj.length > 0) {

			// 将司机信息赋值给pushPassengerPay
			this.getPushConfirmArrival(obj, pushConfirmArrival);
		}

		return pushConfirmArrival;

	}

	/**
	 * @Title: getPassengerPay @Description:
	 *         将Object[]类型转为pushConfirmArrival @param obj 司机信息 @param
	 *         pushPassengerPay 推送对象 @return PushPassengerPay 返回类型 @throws
	 */
	public void getPushConfirmArrival(Object[] obj, PushConfirmArrival pushConfirmArrival) {

		// 司机Id(推送Id)
		if (obj[0] != null) {
			pushConfirmArrival.setDriverId(obj[0].toString());
		}
		// 设备类型
		if (obj[1] != null) {
			// 设备类型 1:iOS 2:Android
			String deviceType = obj[1].toString();

			if (deviceType.equals("1")) { // 设备类型为：iOS
				pushConfirmArrival.setLoginEquipment("iOS");
			} else if (deviceType.equals("2")) { // 设备类型为：Android
				pushConfirmArrival.setLoginEquipment("Android");
			}

		}
		// 司机电话
		if (obj[2] != null) {
			pushConfirmArrival.setTellPhone(obj[2].toString());
		}
		// 乘客姓名
		if (obj[3] != null) {
			pushConfirmArrival.setPassengerName(obj[3].toString());
		}
		// 车牌号
		if (obj[4] != null) {
			pushConfirmArrival.setLisencePlate(obj[4].toString());
		}
		// 司机名称
		if (obj[5] != null) {
			pushConfirmArrival.setDriverName(obj[5].toString());
		}

	}

	/**
	 * @Title: getPushCancelOrderInfo @Description:
	 *         用户取消订单-获取给司机发送短信和推送的消息 @param passengerId 乘客Id @param driverId
	 *         司机Id @author yhq @return PushCancelOrder 返回类型 @throws
	 */
	@Override
	public PushCancelOrder getPushCancelOrderInfo(String passengerId, String driverId) {

		// 创建乘客支付成功，给司机推送Bean
		PushCancelOrder pushCancelOrder = new PushCancelOrder();

		// 根据司机Id,获取司机信息
		Object[] obj = null;
		try {
			obj = super.sqlQueryUnResultObj(UserOrderDaoSql.PASSENGER_PAY_PUSH, false, passengerId, driverId);
		} catch (Exception e) {
			log.info("乘客支付获取推送内容时出现异常  类：" + this.getClass() + " getPassengerPayPushInfo()", e);
		}

		// 判断司机信息是否为空
		if (obj != null && obj.length > 0) {

			// 将司机信息赋值给pushPassengerPay
			this.getPushCancelOrder(obj, pushCancelOrder);
		}

		return pushCancelOrder;
	}

	/**
	 * @Title: getPassengerPay @Description:
	 *         将Object[]类型转为pushConfirmArrival @param obj 司机信息 @param
	 *         pushPassengerPay 推送对象 @return PushPassengerPay 返回类型 @throws
	 */
	public void getPushCancelOrder(Object[] obj, PushCancelOrder pushCancelOrder) {

		// 司机Id(推送Id)
		if (obj[0] != null) {
			pushCancelOrder.setDriverId(obj[0].toString());
		}
		// 设备类型
		if (obj[1] != null) {
			// 设备类型 1:iOS 2:Android
			String userType = obj[1].toString();

			if (userType.equals("1")) { // 设备类型为：iOS
				pushCancelOrder.setLoginEquipment("iOS");
			} else if (userType.equals("2")) { // 设备类型为：Android
				pushCancelOrder.setLoginEquipment("Android");
			}

		}
		// 司机电话
		if (obj[2] != null) {
			pushCancelOrder.setTellPhone(obj[2].toString());
		}
		// 乘客姓名
		if (obj[3] != null) {
			pushCancelOrder.setPassengerName(obj[3].toString());
		}
		// 司机名称
		if (obj[4] != null) {
			pushCancelOrder.setDriverName(obj[4].toString());
		}
		// 车牌号
		if (obj[5] != null) {
			pushCancelOrder.setLisencePlate(obj[5].toString());
		}

	}

	/**
	 * @Title: latelyOrder @Description: 查看用户最近订单 @param reqGetLastUserOrder
	 *         客户端请求参数 @author yhq @return ResGetLastUserOrder 返回类型 @throws
	 */
	@Override
	public Object latelyOrder(DataResponse dataResponse, ReqGetLastUserOrder reqGetLastUserOrder) {

		// 创建存储用户待完成订单的集合对象
		List<Object[]> objects = null;

		try {
			// 根据用户Id获取其待完成订单
			objects = super.sqlQueryListObj(UserOrderDaoSql.GET_LAST_USER_ORDER, false, reqGetLastUserOrder.getUserId(),
					reqGetLastUserOrder.getUserId(), reqGetLastUserOrder.getUserId());

		} catch (Exception e) {
			log.info("根据用户Id获取其待完成订单时出现异常 类：" + this.getClass(), e);
			return 0;
		}

		// 判断该用户是否存在未完成订单
		if (objects == null || objects.size() <= 0) {

			return 1;
		}

		// 查看用户最近订单响应集合Bean
		List<ResGetLastUserOrder> resGetLastUserOrder_list = new ArrayList<ResGetLastUserOrder>();

		for (Object[] obj : objects) {

			// 创建查看最近订单响应Bean
			ResGetLastUserOrder resGetLastUserOrder = this.getResGetLastUserOrder(obj);

			// 判断当前用户角色
			this.setUserType(reqGetLastUserOrder, resGetLastUserOrder);

			// 如果当前用户为乘客
			if (resGetLastUserOrder.getUserType() == 2) {
				resGetLastUserOrder = this.continueGetLastUserOrder(obj, resGetLastUserOrder);
			}

			resGetLastUserOrder_list.add(resGetLastUserOrder);
		}

		return resGetLastUserOrder_list;
	}

	/**
	 * @Title: setUserType @Description: 判断当前用户角色并赋值 @param reqGetLastUserOrder
	 *         请求参数 @param resGetLastUserOrder 响应Bean @return void 返回类型 @throws
	 */
	public void setUserType(ReqGetLastUserOrder reqGetLastUserOrder, ResGetLastUserOrder resGetLastUserOrder) {

		// 本订单中该用户的角色 1：车主2：乘客
		if (ToolUtil.isBlank(resGetLastUserOrder.getGrabOrderUserId())) {

			// 判断如果没有抢单用户
			if (resGetLastUserOrder.getOrderType().equals(1)) {
				resGetLastUserOrder.setUserType(2);// 当前用户角色为乘客
			} else if (resGetLastUserOrder.getOrderType().equals(2)) {
				resGetLastUserOrder.setUserType(1);// 当前用户角色为司机
			}

		} else if (ToolUtil.isNotBlank(resGetLastUserOrder.getGrabOrderUserId())) {

			if (resGetLastUserOrder.getPlaceOrderUserId().equals(reqGetLastUserOrder.getUserId())) {

				if (resGetLastUserOrder.getOrderType().equals(1)) {
					resGetLastUserOrder.setUserType(2);// 当前用户角色为乘客
				} else if (resGetLastUserOrder.getOrderType().equals(2)) {
					resGetLastUserOrder.setUserType(1);// 当前用户角色为司机
				}

			} else if (resGetLastUserOrder.getGrabOrderUserId().equals(reqGetLastUserOrder.getUserId())) {

				if (resGetLastUserOrder.getOrderType().equals(1)) {
					resGetLastUserOrder.setUserType(1);// 当前用户角色为司机
				} else if (resGetLastUserOrder.getOrderType().equals(2)) {
					resGetLastUserOrder.setUserType(2);// 当前用户角色为乘客
				}

			}

		}

	}

	/**
	 * @Title: getResGetLastUserOrder @Description:
	 *         将Object[]转为ResGetLastUserOrder类型 @param obj 用户的待完成订单 @author
	 *         yhq @return ResGetLastUserOrder 返回类型 @throws
	 */
	public ResGetLastUserOrder getResGetLastUserOrder(Object[] obj) {

		// 创建查看最近订单的响应Bean对象
		ResGetLastUserOrder resGetLastUserOrder = new ResGetLastUserOrder();

		// 对方用户Id
		if (obj[0] != null) {
			resGetLastUserOrder.setUserId(obj[0].toString());
		}
		// 对方用户姓名
		if (obj[1] != null) {
			resGetLastUserOrder.setNickName(obj[1].toString());
		}
		// 对方用户头像
		if (obj[2] != null) {
			resGetLastUserOrder.setUserAvatar(ToolUtil.imageAddress(obj[2].toString()));
		}
		// 对方用户电话
		if (obj[3] != null) {
			resGetLastUserOrder.setTelNo(obj[3].toString());
		}
		// 出发时间
		if (obj[4] != null) {
			resGetLastUserOrder.setSetOutTime(DateFormatUtil.getMMddEHHss(obj[4]));
			resGetLastUserOrder.setOutTime((Date) obj[4]);
		}
		// 总金额
		if (obj[5] != null) {
			// 总金额
			resGetLastUserOrder.setTotalMoney(ToolUtil.castDouble(obj[5]));
			// 订单费用
			resGetLastUserOrder.setOrderCost(ToolUtil.castDouble(obj[5]) - 2);
			// 平台费用
			resGetLastUserOrder.setPlatformCost(ToolUtil.castDouble(2));
		}
		// 红包
		if (obj[6] != null) {
			resGetLastUserOrder.setRedBag(ToolUtil.castDouble(obj[6]));
		}
		// 留言
		if (obj[7] != null) {
			resGetLastUserOrder.setMessage(obj[7].toString());
		}
		// 搭乘人数
		if (obj[8] != null) {
			resGetLastUserOrder.setNumber(ToolUtil.castInteger(obj[8]));
		}
		// 开始地址
		if (obj[9] != null) {
			resGetLastUserOrder.setStartAddress(obj[9].toString());
		}
		// 开始经度
		if (obj[10] != null) {
			resGetLastUserOrder.setStartLongitude(ToolUtil.castDouble(obj[10]));
		}
		// 开始纬度
		if (obj[11] != null) {
			resGetLastUserOrder.setStartLatitude(ToolUtil.castDouble(obj[11]));
		}
		// 目的地
		if (obj[12] != null) {
			resGetLastUserOrder.setEndAddress(obj[12].toString());
		}
		// 目的地经度
		if (obj[13] != null) {
			resGetLastUserOrder.setEndLongitude(ToolUtil.castDouble(obj[13]));
		}
		// 目的地纬度
		if (obj[14] != null) {
			resGetLastUserOrder.setEndLatitude(ToolUtil.castDouble(obj[14]));
		}
		// 订单状态
		if (obj[15] != null) {
			resGetLastUserOrder.setOrderStatus(ToolUtil.castInteger(obj[15]));
		}
		// 订单Id
		if (obj[16] != null) {
			resGetLastUserOrder.setOid(obj[16].toString());
		}
		// 下单类型 1：乘客下单 2：车主下单、
		if (obj[17] != null) {
			resGetLastUserOrder.setOrderType(ToolUtil.castInteger(obj[17]));
		}
		// 下单用户Id
		if (obj[18] != null) {
			resGetLastUserOrder.setPlaceOrderUserId(obj[18].toString());
		}
		// 抢单用户Id
		if (obj[19] != null) {
			resGetLastUserOrder.setGrabOrderUserId(obj[19].toString());
		}
		// 订单有效时间
		if (obj[20] != null) {
			resGetLastUserOrder.setOrderValidateTime((Date) obj[20]);
		}
		// 头像缩略图
		if (obj[21] != null) {
			resGetLastUserOrder.setUserTabloidAvatar(ToolUtil.imageAddress(obj[21].toString()));
		}
		// 车辆品牌
		if (obj[22] != null) {
			resGetLastUserOrder.setVehicleType(obj[22].toString());
		}
		// 车辆型号
		if (obj[23] != null) {
			resGetLastUserOrder.setVehicleModel(obj[23].toString());
		}
		// 车辆颜色
		if (obj[24] != null) {
			resGetLastUserOrder.setVehicleColor(obj[24].toString());
		}
		// 车辆图片
		if (obj[25] != null) {
			resGetLastUserOrder.setLicensePlate(obj[25].toString());
		}
		// 车牌号
		if (obj[26] != null) {
			resGetLastUserOrder.setLicensePlate(obj[26].toString());
		}
		// 订单里程
		if (obj[27] != null) {
			resGetLastUserOrder.setDistance(ToolUtil.castDouble(obj[27]));
		}
		// 对方性别
		if (obj[28] != null) {
			resGetLastUserOrder.setSex(ToolUtil.castInteger(obj[28]));
		}
		// 短长途类型
		if (obj[29] != null) {
			resGetLastUserOrder.setIsLongDistance(ToolUtil.castInteger(obj[29]));
		}
		// 用户优惠券Id
		if (obj[30] != null) {
			resGetLastUserOrder.setUcId(obj[30].toString());
		}
		// 优惠金额
		if (obj[31] != null) {
			resGetLastUserOrder.setCouponMoney(ToolUtil.castDouble(obj[31]));
		}
		// 用户级别
		if (obj[32] != null) {
			resGetLastUserOrder.setUserLevel(Float.parseFloat(obj[32].toString()));
		}

		// 添加时间
		resGetLastUserOrder.setCurrentSerTime(new Date());

		return resGetLastUserOrder;
	}

	/**
	 * Description:添加车主信息
	 * 
	 * @param obj
	 * @return
	 */
	private ResGetLastUserOrder continueGetLastUserOrder(Object[] obj, ResGetLastUserOrder resGetLastUserOrder) {

		// 车辆品牌
		if (obj[22] != null) {
			resGetLastUserOrder.setVehicleType(obj[22].toString());
		}
		// 车辆型号
		if (obj[23] != null) {
			resGetLastUserOrder.setVehicleModel(obj[23].toString());
		}
		// 车辆颜色
		if (obj[24] != null) {
			resGetLastUserOrder.setVehicleColor(obj[24].toString());
		}
		// 车辆照片
		if (obj[25] != null) {
			resGetLastUserOrder.setVehicleImage(ToolUtil.imageAddress(obj[25].toString()));
		}
		// 车牌号
		if (obj[26] != null) {
			resGetLastUserOrder.setLicensePlate(obj[26].toString());
		}

		return resGetLastUserOrder;
	}

	/**
	 * @Title: getUserOrder @Description: 获取我的订单 @param reqGetUserOrder
	 *         客户端请求参数 @param dataResponse 响应Bean @author yhq @return Object
	 *         返回类型 @throws
	 */
	@Override
	public Object getUserOrder(DataResponse dataResponse, ReqGetUserOrder reqGetUserOrder) {

		// 创建用于存储我的订单信息的对象
		List<Object[]> objects = null;
		try {

			if (reqGetUserOrder.getOrderStatus() == 4) {

				objects = super.sqlQueryListObj(UserOrderDaoSql.GET_USER_ORDER_COMPLETED, false,
						reqGetUserOrder.getUserId(), reqGetUserOrder.getUserId(), reqGetUserOrder.getUserId(),
						reqGetUserOrder.getOrderStatus(), reqGetUserOrder.getUserId(), reqGetUserOrder.getUserId(),
						(reqGetUserOrder.getPageIndex() - 1) * reqGetUserOrder.getPageSize(),
						reqGetUserOrder.getPageSize());
			} else {

				objects = super.sqlQueryListObj(UserOrderDaoSql.GET_USER_ORDER_CANCELED, false,
						reqGetUserOrder.getUserId(), reqGetUserOrder.getUserId(), reqGetUserOrder.getUserId(),
						reqGetUserOrder.getOrderStatus(), reqGetUserOrder.getUserId(), reqGetUserOrder.getUserId(),
						(reqGetUserOrder.getPageIndex() - 1) * reqGetUserOrder.getPageSize(),
						reqGetUserOrder.getPageSize());
			}

		} catch (Exception e) {
			log.info("查询我的订单时出现异常  类：" + this.getClass() + " getUserOrder()", e);
			return 0;
		}

		// 我的订单-响应客户端请求对象
		ResGetUserOrder resGetUserOrder = new ResGetUserOrder();

		// 创建我的订单的响应对象的子对象
		List<OrderList> orderList = new ArrayList<OrderList>();

		// 判断我的订单是否存在
		if (objects == null || objects.size() <= 0) {

			return 1;
		}

		// 遍历我的订单列表，并转换值
		for (Object[] obj : objects) {
			orderList.add(this.getResGetUserOrder(obj,reqGetUserOrder));
		}

		// 将我的订单列表存入响应bean中
		resGetUserOrder.setOrderList(orderList);

		return resGetUserOrder;
	}

	/**
	 * @Title: getResGetUserOrder @Description:
	 *         将object[]中的值转入resGetUserOrder对象中 @param obj 我的订单信息 @author
	 *         yhq @return ResGetUserOrder 返回类型 @throws
	 */
	public OrderList getResGetUserOrder(Object[] obj,ReqGetUserOrder reqGetUserOrder) {

		// 创建我的订单的响应对象的子对象
		OrderList orderList = new OrderList();

		// 订单类型(1:接乘 2:搭乘)
		if (obj[0] != null) {
			orderList.setOrderType(ToolUtil.castInteger(obj[0]));
		}
		// 出发时间
		if (obj[1] != null) {
			orderList.setSetOutTime(DateFormatUtil.getMMddEHHss(obj[1]));
		}
		// 下单时间
		if (obj[2] != null) {
			orderList.setCreateTime((Date) obj[2]);
		}
		// 总金额
		if (obj[3] != null) {
			// 总金额
			orderList.setTotalMoney(ToolUtil.castDouble(obj[3]));
			// 订单费用
			orderList.setOrderCost(ToolUtil.castDouble(obj[3]) - 2);
			// 平台费用
			orderList.setPlatformCost(ToolUtil.castDouble(2));
		}
		// 起始地
		if (obj[4] != null) {
			orderList.setStartAddress(obj[4].toString());
		}
		// 目的地
		if (obj[5] != null) {
			orderList.setEndAddress(obj[5].toString());
		}
		// 取消原因(1:司机主动取消 2:乘客主动取消 3:自动取消)
		if (obj[6] != null) {
			orderList.setCancelType(ToolUtil.castInteger(obj[6]));
		}
		// 对方用户头像
		if (obj[7] != null) {
			orderList.setUserAvatar(ToolUtil.imageAddress(obj[7].toString()));
		}
		// 对方用户昵称
		if (obj[8] != null) {
			orderList.setNickName(obj[8].toString());
		}
		// 订单Id
		if (obj[9] != null) {
			orderList.setOid(obj[9].toString());
		}
		// 对方头像缩略图地址
		if (obj[10] != null) {
			orderList.setUserTabloidAvatar(ToolUtil.imageAddress(obj[10].toString()));
		}
		// 1：普通 2:长途
		if (obj[11] != null) {
			orderList.setIsLongDistance(ToolUtil.castInteger(obj[11]));
		}
		// 优惠金额
		if (obj[12] != null) {
			orderList.setCouponMoney(ToolUtil.castDouble(obj[12]));
		}
		// 1:司机主动取消2：乘客主动取消
		if (obj[13] != null) {
			orderList.setCancelNumber(ToolUtil.castInteger(obj[13]));
		}
		// 用户级别
		if (obj[14] != null) {
			orderList.setUserLevel(Float.parseFloat(obj[14].toString()));
		}
		// 订单里程
		if (obj[15] != null) {
			orderList.setDistance(ToolUtil.castDouble(obj[15]));
		}
		// 车主赠送积分
		if (obj[16] != null) {
			orderList.setDriverIRcvntegral(ToolUtil.castInteger(obj[16]));
		}
		// 留言
		if (obj[17] != null) {
			orderList.setMessage(obj[17].toString());
		}
		// 合乘人数
		if (obj[18] != null) {
			orderList.setNumber(ToolUtil.castInteger(obj[18]));
		}
		// 是否评价过
		if (obj[19] != null) {
			orderList.setIsComment(ToolUtil.castInteger(obj[19]));
		}
		// 是否评价过
		if (obj[20] != null) {
			orderList.setIsCarShare(ToolUtil.castInteger(obj[20]));
		}
		
		if(obj.length > 21){
			// 取消订单用户Id
			if (obj[21] != null) {
				//判断取消订单用户Id是否等于当前用户Id
				if(obj[21].equals(reqGetUserOrder.getUserId())){
					orderList.setCancelRerson(1);//自己取消
				}else{
					orderList.setCancelRerson(2);//对方取消
				}
			}else{
				orderList.setCancelRerson(3);//自动取消
			}
		}

		return orderList;
	}

	/**
	 * @Title: getNearbyUserList
	 * @Description: 获取附近列表(乘客列表/车主列表)
	 * @param dataResponse
	 * @param reqGetNearbyUserList
	 * @return void 返回类型
	 */
	@Override
	public List<NearbyOrderList> getNearbyUserLists(ReqGetNearbyUserList reqGetNearbyUserList) {

		// 创建用于存储获取附近列表的对象
		List<Object[]> objects = null;

		try {
			// 获取附近列表
			objects = super.sqlQueryListObj(
					UserOrderDaoSql.getNearByUserListNotParam(reqGetNearbyUserList.getSortCondition()), false,
					reqGetNearbyUserList.getUserType(), reqGetNearbyUserList.getUserId(),
					(reqGetNearbyUserList.getPageIndex() - 1) * reqGetNearbyUserList.getPageSize(),
					reqGetNearbyUserList.getPageSize());
		} catch (Exception e) {
			log.info("无筛选条件获取附近列表时出现异常   类：" + this.getClass() + " getNearbyUserLists()", e);
		}

		// 根据用户Id获取开启的路线列表
		List<Userroute> userRoutes = this.getUserRoute(reqGetNearbyUserList.getUserId());

		// 创建用于存储附近列表的变量
		List<NearbyOrderList> list = null;

		// 判断查询的附近列表是否为空
		if (objects != null && objects.size() > 0) {
			list = this.getNearbyUserLists(objects, reqGetNearbyUserList, userRoutes);
		}

		return list;
	}

	/**
	 * @Title: getNearbyOrderLists 
	 * @Description: 获取附近订单列表(V1.9.0新接口)
	 * @param reqGetNearbyOrderList 客户端请求参数
	 * @return List<NearbyOrderList>    返回类型 
	 * @throws
	 */
	@Override
	public List<NearbyOrderList> getNearbyOrderLists(ReqGetNearbyOrderList reqGetNearbyOrderList) {

		// 创建用于存储获取附近列表的对象
		List<Object[]> objects = null;

		try {
			// 获取附近列表
			objects = super.sqlQueryListObj(
					UserOrderDaoSql.getNearByUserListNotParam(reqGetNearbyOrderList.getSortCondition()), false,
					reqGetNearbyOrderList.getUserType(), reqGetNearbyOrderList.getUserId(),
					(reqGetNearbyOrderList.getPageIndex() - 1) * reqGetNearbyOrderList.getPageSize(),
					reqGetNearbyOrderList.getPageSize());
		} catch (Exception e) {
			log.info("无筛选条件获取附近列表时出现异常   类：" + this.getClass() + " getNearbyUserLists()", e);
		}

		// 根据用户Id获取开启的路线列表
		List<Userroute> userRoutes = this.getUserRoute(reqGetNearbyOrderList.getUserId());

		// 创建用于存储附近列表的变量
		List<NearbyOrderList> list = null;

		// 判断查询的附近列表是否为空
		if (objects != null && objects.size() > 0) {
			list = this.getNearbyOrderLists(objects, reqGetNearbyOrderList, userRoutes);
		}

		return list;
	}

	/**
	 * @Title: getUserRoute
	 * @Description: 根据用户Id获取用户开启的路线列表
	 * @param userId
	 *            用户Id
	 * @author yuHaiQing
	 * @return List<Userroute> 返回类型
	 */
	public List<Userroute> getUserRoute(String userId) {

		// 根据用户Id获取其启用的路线列表
		List<Object[]> routeObjects = super.sqlQueryListObj(UserOrderDaoSql.GET_ALL_ENABLE_USERROUTE, false, userId);

		// 创建用于存储用户路线列表的对象
		List<Userroute> userRoutes = new ArrayList<Userroute>();

		// 数据转换(将List<Object[]>类型转为List<Userroute>)
		this.getUserRoutes(routeObjects, userRoutes);

		return userRoutes;
	}

	/**
	 * @Title: getUserRoutes
	 * @Description: 数据转换(将List<Object[]>类型转为List<Userroute>)
	 * @param objects
	 *            路线列表数据
	 * @param userroutes
	 *            存储路线列表对象
	 * @author yuHaiQing
	 * @return void 返回类型
	 */
	public void getUserRoutes(List<Object[]> objects, List<Userroute> userroutes) {

		for (Object[] obj : objects) {

			Userroute userroute = new Userroute();

			// 路线Id
			if (obj[0] != null) {
				userroute.setUrId(obj[0].toString());
			}
			// 出发时间
			if (obj[1] != null) {
				userroute.setSetOutTime((Date) obj[1]);
			}
			// 起点经度
			if (obj[2] != null) {
				userroute.setStartLongitude(ToolUtil.castDouble(obj[2]));
			}
			// 起点纬度
			if (obj[3] != null) {
				userroute.setStartLatitude(ToolUtil.castDouble(obj[3]));
			}
			// 终点经度
			if (obj[4] != null) {
				userroute.setPurposeLongitude(ToolUtil.castDouble(obj[4]));
			}
			// 终点纬度
			if (obj[5] != null) {
				userroute.setPurposeLatitude(ToolUtil.castDouble(obj[5]));
			}
			// 路线类型
			if (obj[6] != null) {
				userroute.setRouteType(ToolUtil.castInteger(obj[6]));
			}

			userroutes.add(userroute);
		}

	}

	/**
	 * @Title: getNearbyUserLists 
	 * @Description: 将List<Object[]>转为List <ResGetNearbyUserList>
	 * @param objects List<Object[]>类型的附近用户列表
	 * @return List<ResGetNearbyUserList> 返回类型
	 */
	public List<NearbyOrderList> getNearbyUserLists(List<Object[]> objects, ReqGetNearbyUserList reqGetNearbyUserList,
			List<Userroute> userRoutes) {

		// 创建用于响应客户端的集合对象(获取附近用户列表集合)
		List<NearbyOrderList> list = new ArrayList<NearbyOrderList>();

		// 获取当前用户订单
		for (Object[] obj : objects) {

			// 判断要使用的字段是否为空
			boolean flag = getOrderListValidate(obj, reqGetNearbyUserList);

			if (!flag) {
				log.info("不符合条件");
				continue;
			}

			// 创建用于存储附近订单的对象
			NearbyOrderList resGetNearbyUserList = new NearbyOrderList();

			// 筛选条件（1：附近 2：顺路 3：长途）
			Integer screenCondition = reqGetNearbyUserList.getScreenCondition();

			// 用户当前位置距离订单起点距离
			BigDecimal currentDistance = this.getCurrentDistance(obj, reqGetNearbyUserList.getCurrentLongitude(),
					reqGetNearbyUserList.getCurrentLatitude());

			// 给订单添加一个用户距离订单起点距离
			resGetNearbyUserList.setStartDistance(currentDistance);

			// 筛选条件（1：附近 2：顺路 3：长途）
			if (screenCondition.equals(1)) { // 附近

				// 判断用户距离订单起点距离是否在规定范围内
				if (currentDistance.compareTo(ServiceCode.NEARBY_RANGE) > 0) {
					continue;
				}

				// 数据转换
				this.nearbyMethod(resGetNearbyUserList, obj);

			} else if (screenCondition.equals(2)) { // 顺路

				// 如果获取到的路线信息为空，则退出本次循环
				if (userRoutes == null || userRoutes.size() <= 0) {
					break;
				}

				this.regularRouteMethod(obj, resGetNearbyUserList, userRoutes);

			} else if (screenCondition.equals(3)) { // 长途
				// 数据转换
				this.longDistanceMethod(obj, resGetNearbyUserList, reqGetNearbyUserList.getPayCity());
			}

			if (resGetNearbyUserList != null && ToolUtil.isNotBlank(resGetNearbyUserList.getOid())) {
				list.add(resGetNearbyUserList);
			}

		}

		if (list != null && list.size() > 0
				&& (reqGetNearbyUserList.getSortCondition() == 3 || reqGetNearbyUserList.getSortCondition() == 1)) {
			Collections.sort(list, new ComparatorUtil());
		}

		return list;
	}

	/**
	 * @Title: getNearbyUserLists 
	 * @Description: 将List<Object[]>转为List <ResGetNearbyUserList>
	 * @param objects List<Object[]>类型的附近用户列表
	 * @return List<ResGetNearbyUserList> 返回类型
	 */
	public List<NearbyOrderList> getNearbyOrderLists(List<Object[]> objects, ReqGetNearbyUserList reqGetNearbyUserList,
			List<Userroute> userRoutes) {

		// 创建用于响应客户端的集合对象(获取附近用户列表集合)
		List<NearbyOrderList> list = new ArrayList<NearbyOrderList>();

		// 获取当前用户订单
		for (Object[] obj : objects) {

			// 判断要使用的字段是否为空
			boolean flag = getOrderListValidate(obj, reqGetNearbyUserList);

			if (!flag) {
				log.info("不符合条件");
				continue;
			}

			// 创建用于存储附近订单的对象
			NearbyOrderList resGetNearbyUserList = new NearbyOrderList();

			// 筛选条件（1：附近 2：顺路 3：长途）
			Integer screenCondition = reqGetNearbyUserList.getScreenCondition();

			// 用户当前位置距离订单起点距离
			BigDecimal currentDistance = this.getCurrentDistance(obj, reqGetNearbyUserList.getCurrentLongitude(),
					reqGetNearbyUserList.getCurrentLatitude());

			// 给订单添加一个用户距离订单起点距离
			resGetNearbyUserList.setStartDistance(currentDistance);

			// 筛选条件（1：附近 2：顺路 3：长途）
			if (screenCondition.equals(1)) { // 附近

				// 判断用户距离订单起点距离是否在规定范围内
				if (currentDistance.compareTo(ServiceCode.NEARBY_RANGE) > 0) {
					continue;
				}

				// 数据转换
				this.nearbyMethod(resGetNearbyUserList, obj);

			} else if (screenCondition.equals(2)) { // 顺路

				// 如果获取到的路线信息为空，则退出本次循环
				if (userRoutes == null || userRoutes.size() <= 0) {
					break;
				}

				this.regularRouteMethod(obj, resGetNearbyUserList, userRoutes);

			} else if (screenCondition.equals(3)) { // 长途
				// 数据转换
				this.longDistanceMethod(obj, resGetNearbyUserList, reqGetNearbyUserList.getPayCity());
			}

			if (resGetNearbyUserList != null && ToolUtil.isNotBlank(resGetNearbyUserList.getOid())) {
				list.add(resGetNearbyUserList);
			}

		}

		if (list != null && list.size() > 0
				&& (reqGetNearbyUserList.getSortCondition() == 3 || reqGetNearbyUserList.getSortCondition() == 1)) {
			Collections.sort(list, new ComparatorUtil());
		}

		return list;
	}

	/**
	 * @Title: getNearbyUserLists 
	 * @Description: 将List<Object[]>转为List <ResGetNearbyUserList>
	 * @param objects List<Object[]>类型的附近用户列表
	 * @return List<ResGetNearbyUserList> 返回类型
	 */
	public List<NearbyOrderList> getNearbyOrderLists(List<Object[]> objects,
			ReqGetNearbyOrderList reqGetNearbyOrderList, List<Userroute> userRoutes) {

		// 创建用于响应客户端的集合对象(获取附近用户列表集合)
		List<NearbyOrderList> list = new ArrayList<NearbyOrderList>();

		// 获取当前用户订单
		for (Object[] obj : objects) {

			// 判断要使用的字段是否为空
			boolean flag = getOrderInfoListValidate(obj, reqGetNearbyOrderList);

			if (!flag) {
				log.info("不符合条件");
				continue;
			}

			// 创建用于存储附近订单的对象
			NearbyOrderList resGetNearbyUserList = new NearbyOrderList();

			// 筛选条件（1：上班 2：下班 3：附近 4：长途）
			Integer screenCondition = reqGetNearbyOrderList.getScreenCondition();

			// 用户当前位置距离订单起点距离
			BigDecimal currentDistance = this.getCurrentDistance(obj, reqGetNearbyOrderList.getCurrentLongitude(),
					reqGetNearbyOrderList.getCurrentLatitude());

			// 给订单添加一个用户距离订单起点距离
			resGetNearbyUserList.setStartDistance(currentDistance);

			// 筛选条件（1：上班 2：下班 3：附近 4：长途）
			if (screenCondition.equals(1)) { // 上班

				// 如果获取到的路线信息为空，则退出本次循环
				if (userRoutes == null || userRoutes.size() <= 0) {
					break;
				}

				this.commuteRouteMethod(obj, resGetNearbyUserList, userRoutes, 1);

			} else if (screenCondition.equals(2)) { // 下班

				// 如果获取到的路线信息为空，则退出本次循环
				if (userRoutes == null || userRoutes.size() <= 0) {
					break;
				}

				this.commuteRouteMethod(obj, resGetNearbyUserList, userRoutes, 2);

			} else if (screenCondition.equals(3)) { // 附近

				// 判断用户距离订单起点距离是否在规定范围内
				if (currentDistance.compareTo(ServiceCode.NEARBY_RANGE) > 0) {
					continue;
				}

				// 数据转换
				this.nearbyMethod(resGetNearbyUserList, obj);

			} else if (screenCondition.equals(4)) { // 长途
				// 数据转换
				this.longDistanceMethod(obj, resGetNearbyUserList, reqGetNearbyOrderList.getPayCity());
			}

			if (resGetNearbyUserList != null && ToolUtil.isNotBlank(resGetNearbyUserList.getOid())) {
				list.add(resGetNearbyUserList);
			}

		}

		if (list != null && list.size() > 0
				&& (reqGetNearbyOrderList.getSortCondition() == 3 || reqGetNearbyOrderList.getSortCondition() == 1)) {
			Collections.sort(list, new ComparatorUtil());
		}

		return list;
	}

	/**
	 * @Title: getOrderListValidate @Description: 获取订单列表验证 @param obj
	 * 订单数据 @param reqGetNearbyUserList 客户端请求参数 @param userRoutes 用户路线列表 @author
	 * yuHaiQing @return boolean 返回类型 @throws
	 */
	public boolean getOrderListValidate(Object[] obj, ReqGetNearbyUserList reqGetNearbyUserList) {

		// 筛选条件（1：附近 2：顺路 3：长途）
		if (reqGetNearbyUserList.getScreenCondition().equals(2)) {
			// 出发时间
			if (obj[4] == null) {
				return false;
			}
			// 起点经度
			if (obj[6] == null) {
				return false;
			}
			// 起点纬度
			if (obj[7] == null) {
				return false;
			}
			// 终点经度
			if (obj[9] == null) {
				return false;
			}
			// 终点纬度
			if (obj[10] == null) {
				return false;
			}

		} else if (reqGetNearbyUserList.getScreenCondition().equals(3)) { // 长途
			// 订单里程
			if (obj[27] == null) {
				return false;
			}
			// 下单城市
			if (obj[28] == null) {
				return false;
			}
		}

		return true;
	}

	/**
	 * @Title: getOrderListValidate 
	 * @Description: 获取订单列表验证 
	 * @param obj 订单数据 
	 * @param reqGetNearbyUserList 客户端请求参数 
	 * @param userRoutes 用户路线列表 
	 * @author yuHaiQing 
	 * @return boolean 返回类型 @throws
	 */
	public boolean getOrderInfoListValidate(Object[] obj, ReqGetNearbyOrderList reqGetNearbyOrderList) {

		// 筛选条件（1：附近 2：顺路 3：长途）
		if (reqGetNearbyOrderList.getScreenCondition().equals(2)) {
			// 出发时间
			if (obj[4] == null) {
				return false;
			}
			// 起点经度
			if (obj[6] == null) {
				return false;
			}
			// 起点纬度
			if (obj[7] == null) {
				return false;
			}
			// 终点经度
			if (obj[9] == null) {
				return false;
			}
			// 终点纬度
			if (obj[10] == null) {
				return false;
			}

		} else if (reqGetNearbyOrderList.getScreenCondition().equals(3)) { // 长途
			// 订单里程
			if (obj[27] == null) {
				return false;
			}
			// 下单城市
			if (obj[28] == null) {
				return false;
			}
		}

		return true;
	}

	/**
	 * @Title: getCurrentDistance 
	 * @Description: 获取当前用户距离订单起点距离 
	 * @author yuHaiQing 
	 * @return double 返回类型 @throws
	 */
	public BigDecimal getCurrentDistance(Object[] obj, double currentLongitude, double currentLatitude) {

		// 订单起点经度
		double startLongitude = ToolUtil.castDouble(obj[6]);
		// 订单起点纬度
		double startLatitude = ToolUtil.castDouble(obj[7]);
		// 用户当前位置经度
		// double currentLongitude = reqGetNearbyUserList.getCurrentLongitude();
		// 用户当前位置纬度
		// double currentLatitude = reqGetNearbyUserList.getCurrentLatitude();

		// 计算用户当前位置距离订单起点位置的距离
		BigDecimal currentDistance = GetDistanceUtil.GetDistance(currentLongitude, currentLatitude, startLongitude,
				startLatitude);

		return currentDistance;
	}

	/**
	 * @Title: nearbyMethod
	 * @Description: 获取订单列表-附近
	 * @param resGetNearbyUserList
	 *            响应Bean
	 * @param obj
	 *            订单数据
	 * @author yuHaiQing
	 * @return ResGetNearbyUserList 返回类型
	 */
	public NearbyOrderList nearbyMethod(NearbyOrderList resGetNearbyUserList, Object[] obj) {

		// 数据转换
		this.getResGetNearByUserList(resGetNearbyUserList, obj);

		return resGetNearbyUserList;
	}

	/**
	 * @Title: regularRouteMethod
	 * @Description: 获取订单列表-顺路
	 * @param obj
	 *            订单数据
	 * @param resGetNearbyUserList
	 *            响应Bean
	 * @param userRoutes
	 *            路线列表
	 * @author yuHaiQing
	 * @return void 返回类型
	 */
	public NearbyOrderList regularRouteMethod(Object[] obj, NearbyOrderList resGetNearbyUserList,
			List<Userroute> userRoutes) {

		// 订单出发时间
		Date currentTime = (Date) obj[4];
		// 订单起点经度
		double startLng = ToolUtil.castDouble(obj[6]);
		// 订单起点纬度
		double startLat = ToolUtil.castDouble(obj[7]);
		// 订单终点经度
		double endLng = ToolUtil.castDouble(obj[9]);
		// 订单终点纬度
		double endLat = ToolUtil.castDouble(obj[10]);

		// 遍历全部路线列表
		for (Userroute userRoute : userRoutes) {

			if (userRoute == null || userRoute.getStartLongitude() == null || userRoute.getStartLatitude() == null
					|| userRoute.getPurposeLongitude() == null || userRoute.getPurposeLatitude() == null) {
				log.info("路线中起点或终点的经纬度为空");
				continue;
			}

			// 用户路线起点距离订单起点距离
			BigDecimal startRange = GetDistanceUtil.GetDistance(startLng, startLat, userRoute.getStartLongitude(),
					userRoute.getStartLatitude());
			// 用户路线终点距离订单终点距离
			BigDecimal endRange = GetDistanceUtil.GetDistance(endLng, endLat, userRoute.getPurposeLongitude(),
					userRoute.getPurposeLatitude());

			// 判断两者的出发时间是否小于30分钟
			long minute = 0;
			try {
				minute = DateFormatUtil.getTimeIntervalS(userRoute.getSetOutTime(), currentTime);
			} catch (Exception e) {
				log.error("获取附近订单-顺路，获取两个时间点的间隔时时出现异常  类：" + this.getClass() + " regularRouteMethod()");
				e.printStackTrace();
			}

			if (startRange.compareTo(new BigDecimal(4)) > 0 || endRange.compareTo(new BigDecimal(4)) > 0 || minute > 30) {
				log.info("顺路匹配订单时，起点距离、终点距离或者出发时间不在规定范围内");
				continue;
			}

			// 数据转换
			this.getResGetNearByUserList(resGetNearbyUserList, obj);

			break;
		}
		return resGetNearbyUserList;
	}

	/**
	 * @Title: regularRouteMethod
	 * @Description: 获取订单列表-顺路
	 * @param obj
	 *            订单数据
	 * @param resGetNearbyUserList
	 *            响应Bean
	 * @param userRoutes
	 *            路线列表
	 * @param routeType 路线类型
	 * @author yuHaiQing
	 * @return void 返回类型
	 */
	public NearbyOrderList commuteRouteMethod(Object[] obj, NearbyOrderList resGetNearbyUserList,
			List<Userroute> userRoutes, Integer routeType) {

		// 订单出发时间
		Date currentTime = (Date) obj[4];
		// 订单起点经度
		double startLng = ToolUtil.castDouble(obj[6]);
		// 订单起点纬度
		double startLat = ToolUtil.castDouble(obj[7]);
		// 订单终点经度
		double endLng = ToolUtil.castDouble(obj[9]);
		// 订单终点纬度
		double endLat = ToolUtil.castDouble(obj[10]);

		// 遍历全部路线列表
		for (Userroute userRoute : userRoutes) {

			if (userRoute == null || userRoute.getStartLongitude() == null || userRoute.getStartLatitude() == null
					|| userRoute.getPurposeLongitude() == null || userRoute.getPurposeLatitude() == null
					|| userRoute.getRouteType() != routeType) {
				log.info("路线中起点或终点的经纬度为空或无该类型路线");
				continue;
			}

			// 用户路线起点距离订单起点距离
			BigDecimal startRange = GetDistanceUtil.GetDistance(startLng, startLat, userRoute.getStartLongitude(),
					userRoute.getStartLatitude());
			// 用户路线终点距离订单终点距离
			BigDecimal endRange = GetDistanceUtil.GetDistance(endLng, endLat, userRoute.getPurposeLongitude(),
					userRoute.getPurposeLatitude());

			// 判断两者的出发时间是否小于30分钟
			long minute = 0;
			try {
				minute = DateFormatUtil.getTimeIntervalS(userRoute.getSetOutTime(), currentTime);
			} catch (Exception e) {
				log.error("获取附近订单-顺路，获取两个时间点的间隔时时出现异常  类：" + this.getClass() + " regularRouteMethod()");
				e.printStackTrace();
			}

			if (startRange.compareTo(new BigDecimal(4)) > 0 || endRange.compareTo(new BigDecimal(4)) > 0 || minute > 30) {
				log.info("顺路匹配订单时，起点距离、终点距离或者出发时间不在规定范围内");
				continue;
			}

			// 数据转换
			this.getResGetNearByUserList(resGetNearbyUserList, obj);

			break;
		}
		return resGetNearbyUserList;
	}

	public NearbyOrderList longDistanceMethod(Object[] obj, NearbyOrderList resGetNearbyUserList, String city) {

		/**
		 * obj[27] 订单里程 obj[28] 下单城市
		 */
		// 订单里程
		double orderDistance = ToolUtil.castDouble(obj[27]);
		// 下单城市
		String payCity = obj[28].toString();

		// 判断出发地是否同城，订单里程是否属于长途拼车范围
		if (!payCity.equals(city) || orderDistance <= 50.0) {
			log.info("不符合长途拼车的筛选条件");
			return null;
		}

		// 数据转换
		this.getResGetNearByUserList(resGetNearbyUserList, obj);

		return resGetNearbyUserList;
	}

	/**
	 * @Title: getResGetNearByUserList @Description: 数据转换 @param
	 * getNearbyUserList 存储订单信息的对象 @param obj 订单信息 @author yuHaiQing @return
	 * ResGetNearbyUserList 返回类型 @throws
	 */
	public NearbyOrderList getResGetNearByUserList(NearbyOrderList getNearbyUserList, Object[] obj) {

		// 乘客Id
		if (obj[0] != null) {
			getNearbyUserList.setPassengerId(obj[0].toString());
		}
		// 订单Id
		if (obj[1] != null) {
			getNearbyUserList.setOid(obj[1].toString());
		}
		// 昵称
		if (obj[2] != null) {
			getNearbyUserList.setNickName(obj[2].toString());
		}
		// 用户头像
		if (obj[3] != null) {
			getNearbyUserList.setUserAvatar(ToolUtil.imageAddress(obj[3].toString()));
		}
		// 出发时间
		if (obj[4] != null) {
			getNearbyUserList.setSetOutTime(DateFormatUtil.getMMddEHHss(obj[4]));
		}
		// 起始地
		if (obj[5] != null) {
			getNearbyUserList.setStartAddress(obj[5].toString());
		}
		// 起始地纬度
		if (obj[6] != null) {
			getNearbyUserList.setStartLongitude(ToolUtil.castDouble(obj[6]));
		}
		// 起始地经度
		if (obj[7] != null) {
			getNearbyUserList.setStartLatitude(ToolUtil.castDouble(obj[7]));
		}

		// 目的地
		if (obj[8] != null) {
			getNearbyUserList.setEndAddress(obj[8].toString());
		}
		// 目的地经度
		if (obj[9] != null) {
			getNearbyUserList.setEndLongitude(ToolUtil.castDouble(obj[9]));
		}
		// 目的地纬度
		if (obj[10] != null) {
			getNearbyUserList.setEndLatitude(ToolUtil.castDouble(obj[10]));
		}
		// 总金额
		if (obj[11] != null) {
			// 总金额
			getNearbyUserList.setTotalMoney(new BigDecimal(obj[11].toString()));
			// 订单费用
			getNearbyUserList.setOrderCost(new BigDecimal(obj[11].toString()).subtract(new BigDecimal(2)));
			// 平台费用
			getNearbyUserList.setPlatformCost(new BigDecimal(2));
		}
		// 距离乘客距离
		if (obj[12] != null) {
			getNearbyUserList.setPassengerDistance(new BigDecimal(obj[12].toString()));
		}
		// 标志
		if (obj[13] != null) {
			getNearbyUserList.setMarker(obj[13].toString());
		}
		// 订单状态
		if (obj[14] != null) {
			getNearbyUserList.setOrderStatus(ToolUtil.castInteger(obj[14]));
		}
		// 红包
		if (obj[15] != null) {
			getNearbyUserList.setRedBag(ToolUtil.castInteger(obj[15]));
		}
		// 留言
		if (obj[16] != null) {
			getNearbyUserList.setMessage(obj[16].toString());
		}
		// 人数
		if (obj[17] != null) {
			getNearbyUserList.setNumber(ToolUtil.castInteger(obj[17]));
		}
		// 手机号
		if (obj[18] != null) {
			getNearbyUserList.setTellPhone(obj[18].toString());
		}
		// 头像缩略图
		if (obj[19] != null) {
			getNearbyUserList.setUserTabloidAvatar(ToolUtil.imageAddress(obj[19].toString()));
		}
		// 总接乘次数
		if (obj[20] != null) {
			getNearbyUserList.setTotalWeldingProcessNumber(ToolUtil.castInteger(obj[20]));
		}
		// 总搭乘次数
		if (obj[21] != null) {
			getNearbyUserList.setTotalTakeNumber(ToolUtil.castInteger(obj[21]));
		}
		// 下单用户性别
		if (obj[22] != null) {
			getNearbyUserList.setSex(ToolUtil.castInteger(obj[22]));
		}
		// 车牌号
		if (obj[23] != null) {
			getNearbyUserList.setLisencePlate(obj[23].toString());
		}
		// 车辆型号
		if (obj[24] != null) {
			getNearbyUserList.setVehicleModel(obj[24].toString());
		}
		// 车辆品牌
		if (obj[25] != null) {
			getNearbyUserList.setVehicleType(obj[25].toString());
		}
		// 车辆颜色
		if (obj[26] != null) {
			getNearbyUserList.setVehicleColor(obj[26].toString());
		}
		// 订单里程
		if (obj[27] != null) {
			getNearbyUserList.setDistance(new BigDecimal(obj[27].toString()));
		}
		// 下单城市
		if (obj[28] != null) {
			getNearbyUserList.setPayCity(obj[28].toString());
		}
		// 订单类型(1:普通 2:长途)
		if (obj[29] != null) {
			getNearbyUserList.setIsLongDistance(ToolUtil.castInteger(obj[29]));
		}
		// 用户级别
		if (obj[30] != null) {
			getNearbyUserList.setUserLevel(Float.parseFloat(obj[30].toString()));
		}

		return getNearbyUserList;
	}

	/**
	 * @Title: getResCompetitiveOrderDetail @Description: 乘客抢单响应给乘客车主信息 @author
	 *         lijinchao @return ResCompetitiveOrder 抢单响应 @throws
	 */
	@Override
	@Transactional(readOnly = true)
	public ResCompetitiveOrder getResCompetitiveOrderDetail(ResCompetitiveOrder resCompetitiveOrder, String uid) {
		// 根据司机id获取其响应抢单响应数据
		Object[] object = sqlQueryUnResultObj(UserOrderDaoSql.PASSAGER_GRABORDER_GES_USER_INFO, false, uid);

		if (object != null) {

			// 司机id
			resCompetitiveOrder.setPublishOrderUserId(uid);
			// 司机昵称
			if (object[0] != null) {
				resCompetitiveOrder.setNickName(object[0].toString());
			}
			// 司机头像
			if (object[1] != null) {
				resCompetitiveOrder.setUserAvatar(ToolUtil.imageAddress(object[1].toString()));
			}
			// 司机车牌
			if (object[2] != null) {
				resCompetitiveOrder.setLicensePlate(object[2].toString());
			}
			// 司机车辆图片
			if (object[3] != null) {
				resCompetitiveOrder.setVehicleImage(ToolUtil.imageAddress(object[3].toString()));
			}
			// 司机车辆颜色
			if (object[4] != null) {
				resCompetitiveOrder.setVehicleColor(object[4].toString());
			}
			// 司机车辆品牌
			if (object[5] != null) {
				resCompetitiveOrder.setVehicleType(object[5].toString());
			}
			// 司机车辆型号
			if (object[6] != null) {
				resCompetitiveOrder.setVehicleModel(object[6].toString());
			}
			// 司机头像缩略图
			if (object[7] != null) {
				resCompetitiveOrder.setUserTabloidAvatar(ToolUtil.imageAddress(object[7].toString()));
			}

			return resCompetitiveOrder;
		}

		return null;
	}

	/**
	 * @Title: getCancelOrders @Description: 获取待取消订单列表 @return List
	 *         <PushAutomaticCancelOrder> 返回类型 @throws
	 */
	@Override
	public List<PushAutomaticCancelOrder> getCancelOrders() {

		// 获取待取消订单
		List<Object[]> objects = null;

		try {
			// 获取待取消订单列表
			objects = super.sqlQueryListObj(UserOrderDaoSql.GET_USER_LIST_BY_CANCEL, false);
		} catch (Exception e) {
			log.error("获取已过期订单时出现异常， 类：" + this.getClass() + " getCancelOrders()", e);
			return null;
		}

		// 判断获取待取消订单是否为空
		if (objects != null && objects.size() > 0) {
			// 如果不为空，则将List<Object[]>转为List<Userordert>
			return this.getUserorderts(objects);
		}

		return null;
	}

	/**
	 * @Title: getConfirmOrders @Description: 获取待自动完成订单列表 @return List
	 *         <PushAutomaticCancelOrder> 返回类型 @throws
	 */
	@Override
	public List<PushAutomaticCancelOrder> getConfirmOrders() {

		// 获取待自动完成订单
		List<Object[]> objects = null;

		try {
			objects = super.sqlQueryListObj(UserOrderDaoSql.AUTO_CONFIRM_ARRIVAL_LIST, false);
		} catch (Exception e) {
			log.error("获取待自动完成订单时出现异常， 类：" + this.getClass() + " getConfirmOrders()", e);
			return null;
		}

		// 判断获取待自动完成订单是否为空
		if (objects != null && objects.size() > 0) {
			// 如果不为空，则将List<Object[]>转为List<Userordert>
			return this.getUserorderts(objects);
		}

		return null;
	}

	// 将List<Object[]>对象转为List<Userordert>，用于存储过期订单信息
	public List<PushAutomaticCancelOrder> getUserorderts(List<Object[]> obj) {

		// 创建用于存储过期订单列表的List<Userordert>对象
		List<PushAutomaticCancelOrder> list = new ArrayList<PushAutomaticCancelOrder>();

		for (Object[] objects : obj) {

			// 创建用于存储订单信息的对象
			PushAutomaticCancelOrder pushAutomaticCancelOrder = new PushAutomaticCancelOrder();

			// 订单Id
			if (objects[0] != null) {
				pushAutomaticCancelOrder.setOid(objects[0].toString());
			}
			// 订单状态
			if (objects[1] != null) {
				pushAutomaticCancelOrder.setOrderStatus(ToolUtil.castInteger(objects[1]));
			}
			// 下单人角色
			if (objects[2] != null) {
				pushAutomaticCancelOrder.setOrderType(ToolUtil.castInteger(objects[2]));
			}
			// 乘客Id
			if (objects[3] != null) {
				pushAutomaticCancelOrder.setPassengerId(objects[3].toString());
			}
			// 乘客设备类型
			if (objects[4] != null) {
				Integer deviceType = ToolUtil.castInteger(objects[4]);
				pushAutomaticCancelOrder.setPassengerEquipment(deviceType == 1 ? "iOS" : "Android");
			}
			// 乘客姓名
			if (objects[5] != null) {
				pushAutomaticCancelOrder.setPassengerName(objects[5].toString());
			}
			// 乘客电话
			if (objects[6] != null) {
				pushAutomaticCancelOrder.setPassengerPhone(objects[6].toString());
			}
			// 司机id
			if (objects[7] != null) {
				pushAutomaticCancelOrder.setDriverId(objects[7].toString());
			}
			// 司机登录设备
			if (objects[8] != null) {
				Integer deviceType = ToolUtil.castInteger(objects[8]);
				pushAutomaticCancelOrder.setDriverEquipment(deviceType == 1 ? "iOS" : "Android");
			}
			// 司机昵称
			if (objects[9] != null) {
				pushAutomaticCancelOrder.setDriverName(objects[9].toString());
			}
			// 司机电话
			if (objects[10] != null) {
				pushAutomaticCancelOrder.setDriverPhone(objects[10].toString());
			}
			// 支付总金额
			if (objects[11] != null) {
				pushAutomaticCancelOrder.setTotalMoney(new BigDecimal(objects[11].toString()));
			}
			// 乘客推送id
			if (objects[12] != null) {
				pushAutomaticCancelOrder.setPassengerAliasId(objects[12].toString());
			}
			// 司机推送id
			if (objects[13] != null) {
				pushAutomaticCancelOrder.setDriverAliasId(objects[13].toString());
			}
			// 总里程
			if (objects[14] != null) {
				pushAutomaticCancelOrder.setDistance(new BigDecimal(objects[14].toString()));
			}
			// 支付宝支付金额
			if (objects[15] != null) {
				pushAutomaticCancelOrder.setAlipayMoney(new BigDecimal(objects[15].toString()));
			}
			// 叮币支付金额
			if (objects[16] != null) {
				pushAutomaticCancelOrder.setPayMoney(new BigDecimal(objects[16].toString()));
			}
			// 优惠金额
			if (objects[17] != null) {
				pushAutomaticCancelOrder.setCouponMoney(new BigDecimal(objects[17].toString()));
			}

			if (objects.length > 18) {
				// 下单时间
				if (objects[18] != null) {
					pushAutomaticCancelOrder.setCreateTime((Date) objects[18]);
				}
				// 出发时间
				if (objects[19] != null) {
					pushAutomaticCancelOrder.setSetOutTime((Date) objects[19]);
				}
				// 起点
				if (objects[20] != null) {
					pushAutomaticCancelOrder.setStartAddress(objects[20].toString());
				}
				// 终点
				if (objects[21] != null) {
					pushAutomaticCancelOrder.setEndAddress(objects[21].toString());
				}
				// 1:普通 2:长途
				if (objects[22] != null) {
					pushAutomaticCancelOrder.setIsLongDistance(ToolUtil.castInteger(objects[22]));
				}
				// 用户优惠券Id
				if (objects[23] != null) {
					pushAutomaticCancelOrder.setUcId(objects[23].toString());
				}
				// 车牌号
				if (objects[24] != null) {
					pushAutomaticCancelOrder.setLisencePlate(objects[24].toString());
				}
			}

			list.add(pushAutomaticCancelOrder);

		}

		return list;
	}

	/**
	 * @Title: getOrderInfo
	 * @Description: 根据订单Id获取订单信息
	 * @param oid
	 *            订单Id
	 * @author yuHaiQing
	 * @return ResGetOrderInfo 返回类型
	 */
	@Override
	public ResGetOrderInfo getOrderInfo(String oid) {

		// 创建用于存储获取附近列表的对象
		Object[] object = null;

		try {

			object = super.sqlQueryUnResultObj(UserOrderDaoSql.GET_ORDER_INFO_BY_ID, false, oid);

		} catch (Exception e) {
			log.info("无筛选条件获取附近列表时出现异常   类：" + this.getClass() + " getNearbyUserLists()", e);
		}

		// 判断获取订单信息是否为空
		if (object != null) {
			return this.geResGetOrderInfo(object);
		}

		return null;
	}

	/**
	 * @Title: geResGetOrderInfo @Description: 数据转换 @param object
	 * 获取到的订单信息 @author yuHaiQing @return ResGetOrderInfo 返回类型 @throws
	 */
	public ResGetOrderInfo geResGetOrderInfo(Object[] object) {

		ResGetOrderInfo resGetOrderInfo = new ResGetOrderInfo();

		// 订单Id
		if (object[0] != null) {
			resGetOrderInfo.setOid(object[0].toString());
		}
		// 用户Id
		if (object[1] != null) {
			resGetOrderInfo.setUserId(object[1].toString());
		}
		// 用户昵称
		if (object[2] != null) {
			resGetOrderInfo.setNickName(object[2].toString());
		}
		// 用户头像
		if (object[3] != null) {
			resGetOrderInfo.setUserAvatar(ToolUtil.imageAddress(object[3].toString()));
		}
		// 对方用户头像
		if (object[4] != null) {
			resGetOrderInfo.setUserTabloidAvatar(ToolUtil.imageAddress(object[4].toString()));
		}
		
		String titleTime = null;
		
		// 出发时间
		if (object[5] != null) {
			
			titleTime = DateFormatUtil.getMMddEHHss(object[5]);
			
			resGetOrderInfo.setSetOutTime((Date) object[5]);
		}
		// 起点
		if (object[6] != null) {
			resGetOrderInfo.setStartAddress(object[6].toString());
		}
		// 起点经度
		if (object[7] != null) {
			resGetOrderInfo.setStartLongitude(ToolUtil.castDouble(object[7]));
		}
		// 起点纬度
		if (object[8] != null) {
			resGetOrderInfo.setStartLatitude(ToolUtil.castDouble(object[8]));
		}
		// 终点
		if (object[9] != null) {
			resGetOrderInfo.setEndAddress(object[9].toString());
		}
		// 终点经度
		if (object[10] != null) {
			resGetOrderInfo.setEndLongitude(ToolUtil.castDouble(object[10]));
		}
		// 终点纬度
		if (object[11] != null) {
			resGetOrderInfo.setEndLatitude(ToolUtil.castDouble(object[11]));
		}
		
		// 下单用户角色
		Integer userType = 0;
		// 总金额
		if (object[12] != null) {
			
			if (object[14] != null) {
				userType = ToolUtil.castInteger(object[14]);
			}
			
			if(userType == 1){	// 司机获取里程费用
				resGetOrderInfo.setTotalMoney(ToolUtil.castDouble(object[12]) + 2);
			}else if(userType == 2){ //乘客需额外支付平台费
				resGetOrderInfo.setTotalMoney(ToolUtil.castDouble(object[12]));
			}

			// 订单费用
			resGetOrderInfo.setOrderCost(ToolUtil.castDouble(object[12]));

			// 平台费用
			resGetOrderInfo.setPlatformCost(2.0);

		}
		// 订单状态(1:待抢单 2:待支付 3:已支付 4:已完成 5:已取消)
		if (object[13] != null) {
			resGetOrderInfo.setOrderStatus(ToolUtil.castInteger(object[13]));
		}
		// 2:乘客下单1：车主下单
		if (object[14] != null) {
			resGetOrderInfo.setUserType(ToolUtil.castInteger(object[14]));
			
			if (userType == 1) {// 车主下单

				// 父订单
				if (object[28] != null) {
					resGetOrderInfo.setParentOrder(object[28].toString());
					resGetOrderInfo.setSubOrder(object[0].toString());
				} else {
					resGetOrderInfo.setParentOrder(object[0].toString());
					resGetOrderInfo.setSubOrder(null);
				}
			} else {// 乘客下单

				// 父订单
				if (object[28] != null) {
					resGetOrderInfo.setParentOrder(object[28].toString());
					resGetOrderInfo.setSubOrder(object[0].toString());
				} else {
					resGetOrderInfo.setParentOrder(null);
					resGetOrderInfo.setSubOrder(object[0].toString());
				}
			}
			
		}
		// 红包
		if (object[15] != null) {
			resGetOrderInfo.setRedBag(ToolUtil.castInteger(object[15]));
		}
		// 留言
		if (object[16] != null) {
			resGetOrderInfo.setMessage(object[16].toString());
		}
		// 人数
		if (object[17] != null) {
			resGetOrderInfo.setNumber(ToolUtil.castInteger(object[17]));
		}
		// 电话
		if (object[18] != null) {
			resGetOrderInfo.setTelePhone(object[18].toString());
		}
		// 性别
		if (object[19] != null) {
			resGetOrderInfo.setSex(ToolUtil.castInteger(object[19]));
		}
		// 车牌号
		if (object[20] != null) {
			resGetOrderInfo.setLisencePlate(object[20].toString());
		}
		// 车辆型号
		if (object[21] != null) {
			resGetOrderInfo.setVehicleModel(object[21].toString());
		}
		// 车辆品牌
		if (object[22] != null) {
			resGetOrderInfo.setVehicleType(object[22].toString());
		}
		// 车辆颜色
		if (object[23] != null) {
			resGetOrderInfo.setVehicleColor(object[23].toString());
		}
		// 订单里程
		if (object[24] != null) {
			resGetOrderInfo.setDistance(ToolUtil.castDouble(object[24]));
		}
		// 订单类型 1:普通 2:长途
		if (object[25] != null) {
			resGetOrderInfo.setIsLongDistance(ToolUtil.castInteger(object[25]));
		}
		// 是否合乘
		if (object[26] != null) {
			resGetOrderInfo.setIsCarShare(ToolUtil.castInteger(object[26]));
		}
		// 出发条件
		if (object[27] != null) {
			resGetOrderInfo.setSetOutCondition(ToolUtil.castInteger(object[27]));
		}
		
		// 用户星级
		if (object[29] != null) {
			resGetOrderInfo.setUserLevel(object[29].toString());
		}
		
		StringBuffer sBuffer = new StringBuffer();

		sBuffer.append(titleTime);

		resGetOrderInfo.setTitle(sBuffer.toString());
		
		return resGetOrderInfo;
	}

	/**
	 * 设置订单为已评价（乘客对车主评价）
	 * @Title: setalreadyEvaluated 
	 * @param orderId 订单ID
	 * @return    设定文件 
	 * @author CHEHAUNBO
	 * 
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean setOrderAlreadyEvaluated(String orderId) {

		try {

			int row = super.updateSqlRow(UserOrderDaoSql.SET_ORDER_ALREADY_EVALUATE, orderId);
			if (row > 0) {
				return true;
			}
		} catch (Exception e) {
			log.error("设置订单为已评价出现异常！订单ID为：" + orderId);
		}
		return false;
	}

	/**
	 * 
	 * 订单完成后，如果用户参加活动有可能赠送积分。
	 * 如果赠送积分需要将获赠积分数更新到订单表中，当前接口由此产生
	 * 
	 * @Title: updateCurrentOrderReceiveIntegral 
	 * @param: receiveIntegral 赠送积分
	 * @para: orderId 订单ID
	 * @return    设定文件 
	 * @author CHEHAUNBO
	 * 
	 */
	@Override
	public boolean updateCurrentOrderReceiveIntegral(BigDecimal receiveIntegral, String orderId) {

		try {

			int row = super.updateSqlRow(UserOrderDaoSql.UPDATE_CURRENTORDER_RECEIVE_INTEGRAL, receiveIntegral,
					orderId);
			if (row > 0) {
				return true;
			}
		} catch (Exception e) {
			log.error("设置订单为已评价出现异常！订单ID为：" + orderId);
		}
		return false;

	}

}
